/**
 * 自定义公共函数
 */
var myfn = {};
/**
 * 测试函数test1
 * vk.myfn.test1();
 */
myfn.test1 = function(obj = {}) {
	let vk = uni.vk;
	console.log("执行了自定义公共函数test1");
	return obj;
};

myfn.cmToPx = function(cm) {
	return Math.floor(cm*28);
};

/**
 * 临时图片路径转base64
 * @param {Object} param 传一个对象，对象里包括
 * url: 临时图片存放路径，选择图片返回的相对路径
 * type: 图片类型，如：png
 */
myfn.blobToBase64 = function (url, type='png') {
    return new Promise((resolve, reject) => {
		uni.request({
		    url: url,
		    method: "GET",
		    responseType: "arraybuffer",
		    success: (ress) => {
		        let base64 = uni.arrayBufferToBase64(ress.data); //把arraybuffer转成base64
				resolve("data:image/" + type.toLocaleLowerCase() + ";base64," + base64);
		    },
		    fail: (res) => reject(res.errMsg),
		});
		
     //    if (uni.getFileSystemManager()) {
     //        uni.getFileSystemManager().readFile({
     //            filePath: url, //选择图片返回的相对路径
     //            encoding: "base64", //编码格式
     //            success: (res) => {
     //                resolve("data:image/" + type.toLocaleLowerCase() + ";base64," + res.data);
     //            },
     //            fail: (res) => reject(res.errMsg),
     //        });
     //    } else {
     //        uni.request({
     //            url: url,
     //            method: "GET",
     //            responseType: "arraybuffer",
     //            success: (ress) => {
     //                let base64 = uni.arrayBufferToBase64(ress.data); //把arraybuffer转成base64
					// resolve("data:image/" + type.toLocaleLowerCase() + ";base64," + base64);
     //            },
     //            fail: (res) => reject(res.errMsg),
     //        });
     //    }
    });
}

export default myfn;
